﻿// Fill out your copyright notice in the Description page of Project Settings.


#include "ResourceOperation/UninstallResources.h"
#include "Engine/AssetManager.h"

void UUninstallResources::UnloadMethod(FSoftObjectPath AssetPath)
{
	FStreamableManager& streamableManager = UAssetManager::GetStreamableManager();
	streamableManager.Unload(FSoftObjectPath(AssetPath));

	// 需要立即回收的话
	// GEngine->ForceGarbageCollection(true);
	// GetWorld()->ForceGarbageCollection(true);
}

void UUninstallResources::ReleaseHandleMethod(FSoftObjectPath AssetPath)
{
	TSharedPtr<FStreamableHandle> Handle1  = UAssetManager::GetStreamableManager().RequestSyncLoad(AssetPath);
	Handle1->ReleaseHandle();
}
void UUninstallResources::ConditionalBeginDestroyMethod()
{
	UMaterial* M_Cube = LoadObject<UMaterial>(nullptr, TEXT("Material'/Game/Geometry/Meshes/CubeMaterial.CubeMaterial'"));
	if (M_Cube)
	{
		M_Cube->ConditionalBeginDestroy();
		M_Cube = nullptr;
		// GetWorld()->ForceGarbageCollection();
	}
}
